import xadmin
from xadmin import views

from . import models


class BaseSetting(object):
    """xadmin的基本配置"""
    enable_themes = True  # 开启主题切换功能
    use_bootswatch = True


xadmin.site.register(views.BaseAdminView, BaseSetting)


class GlobalSettings(object):
    """xadmin的全局配置"""
    site_title = "美多商城运营管理系统"  # 设置站点标题
    site_footer = "美多商城集团有限公司"  # 设置站点的页脚
    menu_style = "accordion"  # 设置菜单折叠


xadmin.site.register(views.CommAdminView, GlobalSettings)


# class SKUAdmin(admin.ModelAdmin): # admin
class SKUAdmin(object):  # xadmin
    # 给模型类标签指定图标
    model_icon = 'fa fa-eye'
    # 指定要显示的列，跟admin是一样的
    list_display = ['id', 'name', 'price', 'stock', 'sales', 'comments']
    # 指定所有的字段
    search_fields = ['id', 'name']
    # 指定过滤字段
    list_filter = ['category']
    # 指定可编辑字段
    list_editable = ['price', 'sales']
    # 指定显示详情的字段
    show_detail_fields = ['name']
    # 显示书签
    show_bookmarks = True
    # 增加导出功能
    list_export = ['xls', 'csv', 'xml']


xadmin.site.register(models.GoodsCategory)
xadmin.site.register(models.GoodsChannel)
xadmin.site.register(models.Goods)
xadmin.site.register(models.Brand)
xadmin.site.register(models.GoodsSpecification)
xadmin.site.register(models.SpecificationOption)
xadmin.site.register(models.SKU, SKUAdmin)
xadmin.site.register(models.SKUSpecification)
xadmin.site.register(models.SKUImage)
